package net.pulseproject.router.config.parser;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

public class LineConfig {
	
	private final String id;
	
	private final String type;
	
	private final Collection<String> outgoingIds;
	
	private final Map<String, Object> properties;
	
	
	public LineConfig(final String id,
					  final String type,
					  final Collection<String> outgoingIds,
					  final Map<String, Object> properties) {
		if(id == null) { throw new IllegalArgumentException("id == null"); }
		if(id.isEmpty()) { throw new IllegalArgumentException("id is empty"); }
		this.id = id;
		
		if(type == null) { throw new IllegalArgumentException("type == null"); }
		if(type.isEmpty()) { throw new IllegalArgumentException("type is empty"); }
		this.type = type;
		
		if(outgoingIds == null) { throw new IllegalArgumentException("outgoingIds == null"); }
		this.outgoingIds = Collections.unmodifiableList(new ArrayList<String>(outgoingIds));
		
		if(properties == null) { throw new IllegalArgumentException("properties == null"); }
		this.properties = Collections.unmodifiableMap(new LinkedHashMap<String, Object>(properties));
	}
	

	public final String getId() {
		return this.id;
	}

	public final String getType() {
		return this.type;
	}

	public final Collection<String> getOutgoingIds() {
		return this.outgoingIds;
	}

	public final Map<String, Object> getProperties() {
		return this.properties;
	}
	
	@Override
	public final boolean equals(final Object other) {
		if((other instanceof LineConfig) == false) {
			return false;
		}
		final LineConfig that = (LineConfig) other;
		return this.id.equals(that.id) &&
			   this.type.equals(that.type) &&
			   this.outgoingIds.equals(that.outgoingIds) &&
			   this.properties.equals(that.properties);
	}
	
	@Override
	public final int hashCode() {
		return this.id.hashCode();
	}
	
	@Override
	public final String toString() {
		return "LineConfig[" +
				"id=[" + this.id + "], " +
				"type=[" + this.getType() + "], " +
				"outgoingIds=" + Arrays.toString(this.outgoingIds.toArray()) + " " +
						"(outgoingIds.size=" + this.getOutgoingIds().size() + "), " +
				"properties.size=" + this.properties.size() +
				"]";
	}
	
}
